package com.it.schoolbookshop_back.mapper;

import com.it.schoolbookshop_back.entities.po.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AdminUserManageMapper {

    /**
     * 管理员获取用户信息
     * @param query 搜索关键词（查询用户名、真实姓名、学号）
     * @param status 筛选状态('active', 'suspended', 'deleted')
     * @param role 筛选角色('student', 'admin')
     * @param sortBy 排序字段('created_at', 'username', 'login_at')
     * @return
     */
    List<User> getUserInform(String query, String status, String role, String sortBy);

    /**
     * 根据用户id获取
     * @param id
     * @return
     */
    @Select("select * from users where id = #{id}")
    User getUserById(int id);

    /**
     * 修改用户状态
     * @param id
     * @param status
     */
    @Update("update users set status = #{status} where id = #{id}")
    void updateStatusById(int id, String status);

    /**
     * 根据用户id重置用户密码
     * @param id
     * @param resetPassword
     */
    @Update("update users set password = #{resetPassword} where id = #{id}")
    void ResetUserPwdById(int id, String resetPassword);

    /**
     * 根据用户id修改用户角色
     * @param id
     * @param role
     */
    @Update("update users set role = #{role} where id = #{id}")
    void UserUpdateRoleById(int id, String role);

    /**
     * 获取全部用户
     * @return
     */
    @Select("select * from users")
    List<User> getAllUser();

    /**
     *
     * @param currentYearMonth
     * @return
     */
    @Select("select * from users where YEAR(created_at) = YEAR(#{currentYearMonth}) " +
            "and MONTH(created_at) =MONTH((#{currentYearMonth}))")
    List<User> getMonthlyNewUsers(String currentYearMonth);

    /**
     *
     * @param string
     * @return
     */
    @Select("select * from users where YEAR(lastLoginAt) = YEAR(#{currentYearMonth}) " +
            "and MONTH(lastLoginAt) =MONTH((#{currentYearMonth}))")
    List<User> getMonthlyActiveUsers(String string);

    /**
     * 根据用户id删除用户
     * @param id 用户ID
     */
    @Delete("DELETE FROM users WHERE id = #{id}")
    void deleteUserById(int id);
}
